<?php
class Todo_model extends Model {
 
    public function Todo_model()
    {
        // model constructor
        parent::Model();
    }
 
    function getCompletedTodo()
    {
        $query = $this->db->get_where('todo', array('status' => '0'));		
        return $query->result();
    }
 
    function getNextTodo()
    {
        $query = $this->db->get_where('todo', array('status' => '1'));	
        return $query->result();
    }

	function add($data)
	{
		$this->db->insert('todo',$data);
	}
	
	function get($id)
	{
		$query = $this->db->get_where('todo', array('id'=>$id));
		if($query->num_rows()==0)
		{
			return false;
		}
		$result = $query->result();
		return $result[0];
	}
	
	function delete($id)
	{
		$query = $this->db->get_where('todo',array('id'=>$id));
		if($query->num_rows()==0)
		{
			return false;
		}
		else
		{
			$this->db->delete('todo',array('id'=>$id));
			return true;
		}
	}
	
	function setComplete($id)
	{
		$query=$this->db->get_where('todo',array('id'=>$id));
		if($query->num_rows()==0)
		{
			return false;
		}
		else
		{
			$this->db->update('todo',array('status'=>0),array('id'=>$id));
			return true;
		}
	}
}?>